package com.grocery.service.impl;

import com.grocery.bean.User;
import com.grocery.dao.UserDao;
import com.grocery.service.ILoginService;
import com.grocery.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Loginservice implements ILoginService {
    @Autowired
    UserDao userDao;
    @Override
    public User dologin(User user) {
        User userdata= userDao.getUserByUsername(user.getUsername());
        if(userdata==null){
            throw new RuntimeException("没有此账号");
        }
        System.out.println(SYS.checkPassword(user.getPassword(),user.getPassword()));
        if(!SYS.checkPassword(user.getPassword(),userdata.getPassword())){
            throw new RuntimeException("密码不正确");
        }
        return userdata;
    }

    @Override
    public User getUserByID(int id) {
        return userDao.getUserByID(id);
    }
}
